﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;
using System.Web;
using System.Data;
using Bzure.Common.Core;
using Bzure.Apps.Security.ViewModels;
using Bzure.Apps.Security;
using Bzure.Apps.Security.Controllers;
using SharpDom.Mvc;


namespace System
{
    public static class ApplicationStartContextSecurityMVCExtensions
    {
        internal static Func<PageControllerItems, IActionFilter> ActionFilterBuilder;
        public static void SetPageFilter(this IApplicationStartContext StartContext, Func<PageControllerItems, IActionFilter> FilterBuilder)
        {
            ActionFilterBuilder = FilterBuilder;
        }
        internal static bool allowAnonymousRegister = true;
        internal static AdministrationRights administrationRight;
        public static void AllowAnonymousRegister(this IApplicationStartContext StartContext, bool IsAllow, AdministrationRights AdministrationRight)
        {
            allowAnonymousRegister = IsAllow;
            administrationRight = AdministrationRight;
        }
        public static void AllowAnonymousRegister(this IApplicationStartContext StartContext, bool IsAllow)
        {
            StartContext.AllowAnonymousRegister(IsAllow, AdministrationRights.UserManage);
        }

        internal static Dictionary<Type, IViewBuilder> pageViews = new Dictionary<Type, IViewBuilder>();
        public static void SetPageView<T>(this IApplicationStartContext StartContext, Func<T, SharpDomView<T>> PageViewBuilder, Func<SiteMaster> MasterViewBuilder) where T : IPageViewModel
        {
            pageViews[typeof(T)] = new ViewBuilder<T>
            {
                MasterBuilder = MasterViewBuilder,
                PageBuilder = PageViewBuilder
            };
        }

    }
}
